package com.dsdl.chatapp.module;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import com.dsdl.chatapp.R;
import com.dsdl.chatapp.module.main.MainActivity;
import com.dsdl.chatapp.module.service.ChatService;
import com.dsdl.chatapp.common.utils.AESUtil;
import com.dsdl.chatapp.common.utils.LogUtil;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String enStr = AESUtil.encode("我这 1231423fkdfjksdf");
        LogUtil.d("zzg","加密后："+enStr);
        String deStr = AESUtil.decode(enStr);
        LogUtil.d("zzg","解密后："+deStr);
        startAnimation();
        startService(new Intent(this, ChatService.class));
    }

    /**
     * 启动动画
     */
    private void startAnimation(){
        final View view = View.inflate(this, R.layout.activity_splash, null);
        setContentView(view);
        // 渐变展示启动屏
        AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
        aa.setDuration(2000);
        view.startAnimation(aa);
        aa.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation arg0) {
                //利用定时器实现跳转
                Timer timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    }
                }, 2000);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationStart(Animation animation) {

            }
        });
    }
}
